package main

import (
	"os"

	"gitee.com/zh-jn/harmonica-previewer-online/api"
	"gitee.com/zh-jn/harmonica-previewer-online/previewer/harmonica/v1/manager"
)

func CollectConfigFromEnv() manager.Config {
	return manager.Config{
		PreviewerPoolNamespace: api.ParseString(os.Getenv("ManagerService_PreviewerPoolNamespace"), "ppool"),
		PreviewerPoolSize:      api.ParseIntValue(os.Getenv("ManagerService_PreviewerPoolSize"), 10),
		PreviewerImageName:     api.ParseString(os.Getenv("ManagerService_PreviewerImageName"), ""),
		SidecarImageName:       api.ParseString(os.Getenv("ManagerService_SidecarImageName"), ""),
		ImagePullSecretName:    api.ParseString(os.Getenv("ManagerService_ImagePullSecretName"), "image-pull-secret"),
		SidecarPort: api.ParseIntValue(os.Getenv("ManagerService_SidecarPort"), 80),
		PreviewerPort: api.ParseIntValue(os.Getenv("ManagerService_PreviewerPort"), 3001),
		Addr: api.ParseString(os.Getenv("ManagerService_Addr"), "0.0.0.0"),
		Port: api.ParseIntValue(os.Getenv("ManagerService_Port"), 8082),
	}
}

var mgr *manager.PreviewerManager

func main() {
	cfg := CollectConfigFromEnv()
	manager.RunServer(cfg)
}
